define(function(require){
	var $=require("jq");
	var Dialog=require("pz_use_dialog.js");
	var cssDialog=require("/pinzhiV2.0/css/pz-dialog.css");// successMod
	/**
	 * 选择银行弹窗
	 * */
	
	$.post("/vipCenter/getWangyinBanks.do",{},function(json){
		var jieji = json.jieji;
		var xiyong = json.xiyong;
		var html = "";
		html +="<dt>银行卡支付：</dt>";
		$.each(jieji,function(i,bank){
			if(bank.code == 310){
				html+=[
						'<dd>',
						'<input type="radio" value="{code}" id="gs-bank-b-{code}" data-card-type="yinhangka" data-type="wangyin" name="bankId" checked><label for="gs-bank-b-{code}"><img width="114" src="{logo}"></label>',
						'</dd>'	
				       ].join("").replace(/{(.*?)}/g,function(s,s1){
				    	   return bank[s1];
				       });
			}else{
				html+=[
						'<dd>',
						'<input type="radio" value="{code}" id="gs-bank-b-{code}" data-card-type="yinhangka" data-type="wangyin" name="bankId"><label for="gs-bank-b-{code}"><img width="114" src="{logo}"></label>',
						'</dd>'	
				       ].join("").replace(/{(.*?)}/g,function(s,s1){
				    	   return bank[s1];
				       });
			}
			
			
			
		});
		
		html+="<dt>信用卡支付：</dt>";
		$.each(jieji,function(i,bank){
			html+=[
					'<dd>',
					'<input type="radio" value="{code}" id="gs-bank-x-{code}" data-card-type="xinyongka" data-type="wangyin" name="bankId"><label for="gs-bank-x-{code}"><img width="114" src="{logo}"></label>',
					'</dd>'	
			       ].join("").replace(/{(.*?)}/g,function(s,s1){
			    	   return bank[s1];
			       });
		});
		
//		html+=[
//		       	'<dt>支付平台：</dt>',
//		       	'<dd>',
//		       		'<input type="radio" data-isKuaiqian="yes" name="bankId" id="qMoney" data-type="kuaiqian" data-card-type="kuaiqian" value="qMoney"><label for="qMoney"><img src="/pinzhiV2.0/pay/Bill99_Banks/99bill.png" width="114"></label>',
//		       	'</dd>'
//		       ].join("");
		
		$("#J_PopupWindow .bank-card-list").html(html);
		//加载完页面以后执行js事件的绑定
		init();
	},"json");
	
	function init(){
		var popWin  = $("#J_PopupWindow"),
		    popMask = $("<div class='g-popup-mask'>"),
		    docElm   = document.documentElement,
		    winWidth = docElm.clientWidth,
		    dlWrap   = popWin.find("dl.bank-card-list");
		
		popWin.before(popMask).css("marginTop",docElm.scrollTop+50);
		dlWrap.css({
			height:docElm.clientHeight*0.7,
			overflowY:"scroll"
		});
		
		
		$(window).resize(function(){
			popWin.css("marginTop",docElm.scrollTop+50);
			dlWrap.css({
				height:docElm.clientHeight*0.5,
				overflowY:"scroll"
			});
		});
	
		var radios        = popWin.find(":radio"),
			bankLogo      = $("dd.selected-bank img"),
			sureBtn       = $("#sure-select-bank-btn"),
			selectBankBtn = $("dd.select-bank-btn");
			
		
		sureBtn.click(function(){
			popWin.fadeOut("fast");
			popMask.fadeOut("fast");
		});
		popMask.click(function(){
			popWin.fadeOut("fast");
			$(this).fadeOut("fast");
		});
		selectBankBtn.click(function(){
			popWin.fadeIn("fast");
			popMask.fadeIn("fast");
		});
		
	
		/**
		 * 提交去充值
		 * */
		var bankIDInput   = $("#js_bankId"),
			bankTypeInput = $("#js_bankType"),
			payMoney      = $("#js_money");
			isWangyinInput = $("#js_isWangyin");
		
		$('#submit').on('click',function(){
			var money = Number(payMoney.val());
			
			if(isNaN(money) || money == 0){
				var tips = new Dialog({
					type:"tips",
					text:"请输入金额",
					delay:1,
					mask:0.3
				});
				return false;
			};
			
			var tips = new Dialog({
				type:"confirm",
				text:"提示信息",
				height:100,
				tipsText:"<p style='text-align:center;font-weight:bold;font-size:14px;'>确认充值吗？</p>",
				callBack:function(){
					$('#rechargeForm').submit();	
				},
				mask:.5
			});
		});
			
		radios.click(function(){
			var bankID = this.value,
				bankType = $(this).attr("data-card-type");
				logoSrc  = $(this).next().find("img").prop("src");
				isKuaiqian = $(this).attr("data-isKuaiqian")=="yes"?1:0;
			
			bankIDInput.val(bankID);
			bankTypeInput.val(bankType);
			bankLogo.prop("src",logoSrc);
			isWangyinInput.val(isKuaiqian==1?0:1);
			
		});
		
//		$("#J_PopupWindow .bank-card-list input").eq(0).click();
		$("#qMoney").click();
		
		/**
		 * 查看各银行充值额度
		 * */
		$("#js_view_limit").click(function(){
			var tips = new Dialog({
				text:"各银行使用额度",
				height:500,
				width:600,
				tipsText:"<table id='bank-list-limit'><tr><td rowspan='2'>银行</td><td colspan='2'>借记卡额度</td><td colspan='2'>信用卡额度</td></tr><tr><td>单笔</td><td>日累计</td><td>单笔</td><td>日累计</td></tr><tr><td>华夏银行</td><td>1万</td><td>1万</td><td>1万</td><td>1万</td></tr><tr><td>中信银行</td><td>&nbsp;</td><td>&nbsp;</td><td>信用额度</td><td>信用额度</td></tr><tr><td>浦发银行</td><td>2万</td><td>2万</td><td>2万</td><td>2万</td></tr><tr><td>建设银行</td><td>1万</td><td>1万</td><td>1万</td><td>1万</td></tr><tr><td>光大银行</td><td>2万</td><td>2万</td><td>5000</td><td>5000</td></tr><tr><td>杭州银行</td><td>5000</td><td>5000</td><td>2万</td><td>2万</td></tr><tr><td>中国银行</td><td>1万</td><td>1万</td><td>信用额度</td><td>信用额度</td></tr><tr><td>民生银行</td><td>5000</td><td>5000</td><td>2万</td><td>2万</td></tr><tr><td>农业银行</td><td>1万</td><td>1万</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>上海银行</td><td>5万</td><td>无限额</td><td>2万</td><td>信用额度</td></tr><tr><td>南京银行</td><td>&nbsp;</td><td>&nbsp;</td><td>2万</td><td>2万</td></tr><tr><td>工商银行</td><td>5000</td><td>5000</td><td>5000</td><td>5万</td></tr><tr><td>交通银行</td><td>5万</td><td>5万</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>招商银行</td><td>2万</td><td>2万</td><td>3万（实物）</td><td>3万（实物）</td></tr><tr><td>兴业银行</td><td>5000</td><td>5000</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>广发银行</td><td>2万</td><td>2万</td><td>2万</td><td>2万</td></tr></table>",
				mask:0.3
			});
			tips.J_PZDialog_content.css("overflow","auto");
		});
		
	}
});